use std::{io::stdin, sync::mpsc::Sender, thread};
use termion::{event::*, input::TermRead};

pub fn capture(sender: Sender<bool>) {
  thread::spawn(|| start_input_capture(sender));
}

fn start_input_capture(sender: Sender<bool>) {
  for c in stdin().events() {
    let evt = c.expect("Unable to capture stdin event. Exiting.");
    if let Event::Key(Key::Ctrl('c')) = evt {
      if sender.send(true).is_err() {
        println!("Error killing renderer. Terminal might look strange.")
      }
      break;
    }
  }
}
